package net.qhzw.vip.qiyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.qhzw.vip.qiyu.entity.UserHealthyLog;
import net.qhzw.vip.qiyu.mapper.UserHealthyLogMapper;
import net.qhzw.vip.qiyu.service.UserHealthyLogService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

@Service
public class UserHealthyLogServiceImpl extends ServiceImpl<UserHealthyLogMapper, UserHealthyLog> implements UserHealthyLogService {

    /***
     * 健康上报
     * @param userId
     * @param userHealthyLog
     * @return
     */
    @Override
    public boolean healthReport(String userId, UserHealthyLog userHealthyLog) {
        userHealthyLog.setId(IdWorker.get32UUID());
        userHealthyLog.setUserId(userId);
        userHealthyLog.setCreated(new Date());
        return save(userHealthyLog);
    }

    /****
     * 获取每日上报列表
     * @param userId
     * @return
     */
    @Override
    public List<UserHealthyLog> findList(String userId) {
        return list(new LambdaQueryWrapper<UserHealthyLog>()
                .eq(UserHealthyLog::getUserId, userId));
    }

    /***
     * 分页获取用户每日上报日志
     * @param page
     * @param userId
     * @param realName
     * @return
     */
    @Override
    public Page<UserHealthyLog> findByPage(Page<UserHealthyLog> page, String userId, String realName) {
        Page<UserHealthyLog> healthyLogPage = page(page, new LambdaQueryWrapper<UserHealthyLog>()
                .eq(!StringUtils.isEmpty(userId), UserHealthyLog::getUserId, userId)
        );
        return healthyLogPage;
    }
}
